package test03;

public class PalindromeList {
    public boolean chkPalindrome(ListNode A) {
        if (A == null) return false;
        ListNode  slow = A;
        ListNode fast = A;
        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
        }
        ListNode cur = slow.next;
        while (cur != null) {
            ListNode curNext = cur.next;
            cur.next = slow;
            slow = cur;
            cur = curNext;
        }

        if(A != slow){
            if(A.val != slow.val) return false;
            if(A.next == slow){
                return true;
            }
            A = A.next;
            slow = slow.next;
        }
        return true;

    }
}